package com.itawei.d6_threadsafe;

public class MyRunnable implements Runnable {
    int ticket = 0;

    @Override
    public void run() {
        //卖一百张电影票
        method();

    }
        //同步方法
    public synchronized void method() {
        //1.循环
        while (true) {
            //2.同步代码块
            //3.判断共享数据是否到末尾 到了
            if (ticket == 100) {
                break;
            } else {
                //4.判断共享数据是否到末尾 没到
                ticket++;
                System.out.println(Thread.currentThread().getName() + "正在卖第" + ticket + "张票");

            }
        }
    }
}
